home *** CD-ROM | disk | FTP | other *** search
- Path: guitar.hal.com!not-for-mail
- From: blair@hal.COM (Blair Martin)
- Newsgroups: comp.lang.c++
- Subject: Interpreting whitespace w. cin
- Date: 30 Jan 1996 15:56:41 -0800
- Organization: HaL Computer Systems, Inc.
- Message-ID: <4emb7p$u0@guitar.hal.com>
- NNTP-Posting-Host: guitar.hal.com
-
- I want to write a program that uses new and delete to dynamically
- allocate exactly enough free memory to hold string input data.
-
- That is, instead of allocating a fixed array of
- characters from the stack, receive one character at a time and
- continually allocate, copy, and release space so that the physical
- and logical lengths of the buffer area are always the same.
- When the newline character is encountered, print the string
- and release the space. Then prompt for the next string. When
- EOF is entered, terminate the program.
-
-
- The problem is with a loop like
-
- while (!(cin >> input).eof())
- {
- ...
- }
-
- there is no way to know when a newline is encountered since
- all whitespace is ignored.
-
- Is there another way to do this?
-
-
- blair
-